/**
 * @project spring-threadpool-async
 * @description
 * @errorcode SystemException</ br>
 * @author 2022 8:56 huzhengyang Create 1.0 <br>
 * @copyright ©2022-2023
 */

package com.teradata.async.dto;

public class ResultUtil {
    public static <T> Result<T> success(T obj) {
        Result<T> result = new Result<>();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMsg(ResultCode.SUCCESS.getTip());
        result.setData(obj);
        return result;
    }

    public static <T> Result<T> error(ResultCode resultCode, String msg) {
        Result<T> result = new Result<>();
        result.setCode(resultCode.getCode());
        result.setMsg(String.format("%s: [%s]", resultCode.getTip(), msg));
        return result;
    }

    public static <T> Result<T> error(ResultCode resultCode, String msg, T data) {
        Result<T> result = new Result<>();
        result.setCode(resultCode.getCode());
        result.setMsg(String.format("%s: [%s]", resultCode.getTip(), msg));
        result.setData(data);
        return result;
    }

    public static <T> Result<T> error(Exception e) {
        Result<T> result = new Result<>();
        result.setCode(ResultCode.SYSTEM_UNKNOWN_ERROR.getCode());
        result.setMsg(String.format("%s: [%s]", ResultCode.SYSTEM_UNKNOWN_ERROR.getTip(), e.getMessage()));
        return result;
    }
}
